//
//  KAMessageViewController.m
//  KeepAccounts
//
//  Created by honeyrr on 2017/10/30.
//  Copyright © 2017年 honeyrr. All rights reserved.
//

#import "KAMessageViewController.h"
#import "KAMsgTableViewCell.h"


static NSString *const msgID = @"msgCell";
@interface KAMessageViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *msgTableIView;

@property(nonatomic, strong) NSArray *tableArr;
@end

@implementation KAMessageViewController

-(NSArray *)tableArr
{
    if (!_tableArr) {
        _tableArr = [NSArray array];
    }
    return _tableArr;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationItem.title = @"消息中心";
    NSArray *arrDict = [[KADataBase instance] queryWithAllDate];
    NSMutableArray *marr = [NSMutableArray array];
    for (NSInteger i = arrDict.count - 1; i >= 0; i--) {
        KADataBaseModel *dbModel = [KADataBaseModel dbWithDict:arrDict[i]];
        [marr addObject:dbModel];
    }
    self.tableArr = marr;
    [self.msgTableIView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.msgTableIView registerNib:[UINib nibWithNibName:NSStringFromClass([KAMsgTableViewCell class]) bundle:nil] forCellReuseIdentifier:msgID];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tableArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    KAMsgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:msgID];
    if (!cell) {
        cell = [[KAMsgTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.msgModel = self.tableArr[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

@end
